package bo.gustavo.scrapper.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;

@Entity
@Table(name = "app_data")
public class AppData {

	private Long id;

	private String title;

	private String developerName;

	private String developerWebsite;

	private String appURL;

	private int reviewAmount;

	private String developerEmail;

	private String category;

	private boolean paid;

	@Id
	@Column(name = "id")
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public AppData() {

	}

	public AppData(String title, String developerName, String developerWebsite, int reviewAmount, String developerEmail, String category, boolean paid) {
		this.title = title;
		this.developerName = developerName;
		this.developerWebsite = developerWebsite;
		this.reviewAmount = reviewAmount;
		this.developerEmail = developerEmail;
		this.category = category;
		this.paid = paid;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "developer_name")
	public String getDeveloperName() {
		return developerName;
	}

	public void setDeveloperName(String developerName) {
		this.developerName = developerName;
	}

	@Column(name = "developer_website")
	public String getDeveloperWebsite() {
		return developerWebsite;
	}

	public void setDeveloperWebsite(String developerWebsite) {
		this.developerWebsite = developerWebsite;
	}

	@Column(name = "app_url")
	public String getAppURL() {
		return appURL;
	}

	public void setAppURL(String appURL) {
		this.appURL = appURL;
	}

	@Column(name = "review_amount")
	public int getReviewAmount() {
		return reviewAmount;
	}

	public void setReviewAmount(int reviewAmount) {
		this.reviewAmount = reviewAmount;
	}

	public void setDeveloperEmail(String developerEmail) {
		this.developerEmail = developerEmail;
	}

	@Column(name = "developer_email")
	public String getDeveloperEmail() {
		return developerEmail;
	}

	@Column(name = "is_paid")
	public boolean isPaid() {
		return paid;
	}

	public void setPaid(boolean isPaid) {
		this.paid = isPaid;
	}

	@Column(name = "category")
	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	@Override
	public String toString() {
		return "AppData [title=" + title + ", developerName=" + developerName + ", developerWebsite=" + developerWebsite + ", appURL="
				+ ", reviewAmount=" + reviewAmount + ", developerEmail=" + developerEmail + "]";
	}

	public String toJSON() {
		return "[\"" + StringUtils.replace(StringUtils.defaultIfEmpty(title, ""), "\"", "\\\"") + "\", \""
				+ StringUtils.replace(StringUtils.defaultIfEmpty(developerName, ""), "\"", "\\\"") + "\", \""
				+ StringUtils.defaultIfEmpty(developerWebsite, "") + "\", \"" + StringUtils.defaultIfEmpty(developerEmail, "") + "\", \""
				+ StringUtils.defaultIfEmpty(appURL, "") + "\",\"" + reviewAmount + "\", \"" + BooleanUtils.toString(paid, "Yes", "No") + "\", \""
				+ StringUtils.defaultIfEmpty(category, "") + "\"]";
	}

}
